//
//  ViewController3.swift
//  Test3
//
//  Created by 王冲 on 2019/1/31.
//  Copyright © 2019年 JK科技有限公司. All rights reserved.
//

import UIKit

class ViewController3: UIViewController {

    var urlString:String?
    
    
    override func viewDidLoad() {
        super.viewDidLoad()

        self.title = "ViewController3"
        view.backgroundColor = UIColor.red
        
        view.addSubview(button1)
    }
    
    // MARK:返回自己的app
    @objc func click(){
        
        let url = NSURL(string: (urlString!+"://"))
        
        if !UIApplication.shared.canOpenURL(url! as URL) {
            return
        }
        
        if #available(iOS 10.0, *) {
            
            UIApplication.shared.open(url! as URL, options: [:]) { (success) in
                
                if (success) {
                    
                    print("10以后可以跳转url")
                    
                }else{
                    
                    print("10以后不能完成跳转")
                    
                }
            }
        } else {
            // Fallback on earlier versions
            let success = UIApplication.shared.openURL(url! as URL)
            
            if (success) {
                
                print("10以下可以跳转")
                
            }else{
                
                print("10以下不能完成跳转")
                
            }
            
        }
        
    }
    
    
    lazy var button1:UIButton = {
        
        let button1 = UIButton(frame: CGRect(x: 50, y: 200, width: UIScreen.main.bounds.size.width-100, height: 50))
        button1.addTarget(self, action: #selector(click), for: UIControl.Event.touchUpInside)
        button1.backgroundColor = UIColor.brown
        button1.setTitle("返回自己的app", for: UIControl.State.normal)
        return button1;
    }()

}
